import scrapy


class TestpostSpider(scrapy.Spider):
    name = "testpost"
    allowed_domains = ["fanyi.baidu.com"]

    # start_urls = ["https://fanyi.baidu.com/sug"]
    #
    # def parse(self, response):
    #     pass

    # post请求
    def start_requests(self):
        url = 'https://fanyi.baidu.com/sug'
        data = {
            'kw': 'successful'
        }

        yield scrapy.FormRequest(url=url, formdata=data, callback=self.parse_post)

    def parse_post(self, response):
        content = response.text

        import json
        print(json.loads(content))
